package com.example.elmspringboot.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.elmspringboot.mapper.BusinessMapper;
import com.example.elmspringboot.domain.Business;
import com.example.elmspringboot.service.BusinessService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business> implements BusinessService {
    @Resource
    private BusinessMapper businessMapper;
    @Override
    public List<Business> selectBusinessByName(String name) {
        QueryWrapper<Business> wrapper=new QueryWrapper<>();
        List<Business> list=businessMapper.selectList(wrapper.like("business_name", name));
        return list;
    }

    @Override
    public Boolean login(String name, String password) {
        LambdaQueryWrapper<Business> wrapper=new LambdaQueryWrapper<>();
        List<Business> business = businessMapper.selectList(wrapper.eq(name != null, Business::getName, name));
        Business business1 = business.get(0);
        if(business1==null){
            return false;
        }
        return business1.getPassword().equals(password);
    }

    @Override
    public IPage<Business> getPage(int currentPage, int pageSize, Business business) {
        IPage page=new Page(currentPage,pageSize);
        LambdaQueryWrapper<Business> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(business.getName()),Business::getName,business.getName());
        return businessMapper.selectPage(page,wrapper);
    }

    @Override
    public Boolean register(String username, String password) {
        return null;
    }

}
